package com.wj.opratorlog.service.impl;

import com.wj.opratorlog.Emums.ActionEnum;
//import com.wj.opratorlog.dao.OperatorMapper;
//import com.wj.opratorlog.entity.OperatorLog;
import com.wj.opratorlog.pojo.OperationLogInfo;
import com.wj.opratorlog.pojo.OperationLogReq;
import com.wj.opratorlog.service.OperatorService;
import org.slf4j.MDC;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

@Service
public class OperatorServiceImp implements OperatorService {


    ApplicationContext applicationContext;
//    @Autowired
//    private OperatorMapper operatorMapper;

    /**
     *  保存日志
     * @param operationLogReq
     */

    @Override
    public void saveLog(  OperationLogReq operationLogReq) {

        String name=null;
        if(Objects.isNull(name)){
                    }
//        OperationLogInfo operationLogInfo = operationLogReq.getOperationLogInfo();
//        OperatorLog operatorLog=null;
//        switch (  operationLogReq.getActionEnum()){
//            case  ADD:
//                  operatorLog = new OperatorLog();
//                operatorLog.setCreateTime(new Date());
//                operatorLog.setOperationTime(new Date());
//                operatorLog.setOperation(operationLogReq.getActionEnum().getCode());
//                BeanUtils.copyProperties(operationLogInfo,operatorLog);
//
//                break;
//            case  EDIT:
//
//                BeanUtils.copyProperties(operationLogInfo,operatorLog);
//
//                operatorLog = new OperatorLog();
//                operatorLog.setCreateTime(new Date());
//                operatorLog.setOperationTime(new Date());
//                operatorLog.setOperation(operationLogReq.getActionEnum().getCode());
//                 break;
//            case  DEL:
//                operatorLog = new OperatorLog();
//                operatorLog.setCreateTime(new Date());
//                operatorLog.setOperationTime(new Date());
//                operatorLog.setOriginalPK(operationLogReq.getOperationLogInfo().getOperationID() );
//                operatorLog.setOperation(operationLogReq.getActionEnum().getCode());
//                break;
//        }
//
//        operatorMapper.insert(operatorLog);
    }

    @Override

    @Async()
    public  CompletableFuture<String> execute(String value) {

         String userId = MDC.get("userId");
        MDC.put("userId","qe30qe0e320e09");
        return CompletableFuture.completedFuture(userId);
    }
}
